<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>LocalStorage</title>
</head>
<body>
    <button onclick="addData()">点我添加数据</button>
    <button onclick="getData()">点我获取数据</button>
    <button onclick="removeData()">点我删除数据</button>
    <button onclick="clearData()">点我清空数据</button>
    <script>
        function addData() {
            // 注意：这里会将所有的value变成字符串 包括一个对象
            localStorage.setItem('name','cty');
            localStorage.setItem('age',21);
            // 用JSON.stringify方法可以解决这个问题
            localStorage.setItem('lisi',JSON.stringify({name:'李四',age:18,hobby:['唱','跳','rap','打篮球']}));
        };
        function getData() {
            console.log(localStorage.getItem('lisi'));
        };
        function removeData() {
            localStorage.removeItem('lisi');
        };
        function clearData() {
            localStorage.clear();
        }
    </script>
</body>
</html>